package com.lhd.controller;

import com.aliyun.oss.model.LiveChannelListing;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.pojo.Result;
import com.lhd.pojo.User;
import com.lhd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @author liuhd
 * @create 2024/10/8 15:03
 **/

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/info")
    public Result getInfo(){
        User user = userService.getInfo();
        return Result.success(user);
    }
    @PatchMapping("/avatar")
    public Result updateAvatar(String url){
        userService.updateAvatar(url);
        return Result.success();
    }
    @PatchMapping("/username")
    public Result updateUsername(String username){
        userService.updateUsername(username);
        return Result.success();
    }
    @PatchMapping("/password")
    public Result updatePassword(@RequestBody User user){
        userService.updatePassword(user.getPassword());
        return Result.success();
    }

    @PutMapping("/ptsAndCrs")
    public Result updatePtsAndCrs(Integer credit,Integer pts){
        userService.updatePtsAndCrs(credit,pts);
        return Result.success();
    }
    @GetMapping("/order")
    public Result getOrder(){
        List<User> userList = userService.getOrder();
        return Result.success(userList);
    }
    @GetMapping("/condition")
    public Result getWithCondition(String username,Integer credit, Integer identity ,Integer point,PageCondition pageCondition){
        PageBean<User> pageBean = userService.getWithCondition(username,credit,identity,point,pageCondition);
        return Result.success(pageBean);
    }
    @PatchMapping("/credit")
    public Result updateCredit(Integer credit,Integer id){
        userService.updateCredit(credit,id);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody User user){
        userService.update(user);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id){
        userService.remove(id);
        return Result.success();
    }
}
